<?php
class controller_cache extends model_cache{
    public function update()
    {
        $keys = $this->existsKeyInArray('keys',$_GET,'S');
        $key = $this->existsKeyInArray('key',$_GET,'S');
        if(!empty($keys))
        {
            $allkeys = $this->redis->keys($keys.'*');
            foreach($allkeys as $k=>$v){
                $this->redis->del($v);
            }
            switch($keys) {
                case 'games_list_and_item':
                    $keys = $this->redis->keys('games_item_forid*');
                    $this->redis->del($keys);
                    $keys = $this->redis->keys('games_paras_odds_*');
                    $this->redis->del($keys);
                    $this->redis->del('game_list_all');
                    break;
                case 'game_sys_paras_':
                    $this->redis->del('games_sys_config');
                    break;
                default:
                    $this->redis->del($key);
                    break;
            }

            $this->dialogue(array(
                'type' => 'success',
                'text' => $keys."* - 更新成功",
                'auto' => true,
                'yes'  => array(
                    'text' => '我知道了',
                    'func' => '$("#btn_refresh").trigger("click");',
                ),
            ));
        }
        if(!empty($key))
        {
            if($key=='all'){
                $allkeys = $this->redis->keys($keys.'*');
                foreach($allkeys as $k=>$v){
                    if(false===strpos($v,'games_doing')
                        && false===strpos($v,'games_issue')
                        && false === strpos($v, 'games_item_for')
                        && false === strpos($v, 'game_myuser')
                    ){
                        $this->redis->del($v);
                    }
                }
                // $this->redis->flushALL();
            }else {
                switch($key) {
                    case 'games_list_and_item':
                        $keys = $this->redis->keys('games_item_forid*');
                        $this->redis->del($keys);
                        $keys = $this->redis->keys('games_paras_odds_*');
                        $this->redis->del($keys);
                        $this->redis->del('game_list_all');
                        break;
                    case 'game_sys_paras_agentupdategiveway':
                        # 删除代理等级列表
                        $this->redis->del('game_agent_level_list');
                        break;
                    case 'game_sys_paras_vipupdategiveway':
                        # 删除 VIP 等级列表
                        $this->redis->del('game_user_level_list');
                        break;
                    default:
                        $this->redis->del($key);
                        break;
                }
                if(substr($key,0,15) == 'game_sys_paras_'){
                    $this->redis->del('games_sys_config');
                }
            }
            $this->dialogue(array(
                'type' => 'success',
                'text' => $key." - 更新成功",
                'auto' => true,
                'yes'  => array(
                    'text' => '我知道了',
                    'func' => '$("#btn_refresh").trigger("click");',
                ),
            ));
        }
    }

    public function update_list()
    {

    }
}